package cn.learn.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 两种标签的区别：
 * 标签：@ConditionalOnProperty可以支持多个 逻辑与 的条件，如 @ConditionalOnProperty(name={"app.initialize.dictionary","app.initialize.all"}, havingValue="true")；
 * 标签：@ConditionalOnExpression可以支持多个表达式，如      @ConditionalOnExpression("${app.initialize.dictionary:false} || ${app.initialize.all:false}")
 * <p>
 * swagger配置类，也可以用标签 @ConditionalOnProperty(value = "swagger.enabled", havingValue = "true")
 *
 * @author huangyezhan
 * @date 2020年2月15日22:28:19
 */
@ConditionalOnExpression("${swagger.enabled:true}")
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket productApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("cn.learn.controller"))
                //.paths(regex("/freeman/mgrsite.*"))
                .build();
    }

}
